package com.lcf.app.kingbase8;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcf.app.kingbase8.entity.User;
import com.lcf.app.kingbase8.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Slf4j
@SpringBootApplication
@MapperScan(basePackages = {"com.lcf.app.kingbase8.mapper"})
public class KingbaseApplication {

    public static void main(String[] args) {
        SpringApplication.run(KingbaseApplication.class, args);
    }

    @Autowired
    private UserService userService;

    /**
     * 测试
     */
    @PostConstruct
    public void test() {
        // 添加
        User chenFei = new User()
                .setAge(18)
                .setBirthday(LocalDate.now())
                .setDataJson("{\"name\":\"ZhangSan\"}")
                .setUsername("ChenFei")
                .setCreateTime(LocalDateTime.now());
        userService.save(chenFei);
        log.info("添加成功 id : {}", chenFei.getId());
        //
        User byId = userService.getById(chenFei.getId());
        log.info("单个查询：{}", byId.toString());
        //
        Page<User> userPage = userService.pageInfo(new Page<>(1, 10));
        log.info("分页查询：{}", userPage.toString());
        //


    }

}
